import {fromJS} from 'immutable'
import * as actionTypes from './actionTypes'

const defaultSate = fromJS({
    topicList: [],
    articleList: [],
    recommendList: [
        {
            id: 1,
            url: require('../../../static/pic1.png')
        },
        {
            id: 2,
            url: require('../../../static/pic2.png')
        },
        {
            id: 3,
            url: require('../../../static/pic3.png')
        },
        {
            id: 4,
            url: require('../../../static/pic4.png')
        },
        {
            id: 5,
            url: require('../../../static/pic5.png')
        }
    ],
    showScroll:false
})

export default (state = defaultSate, action) => {
    switch (action.type) {
        case actionTypes.CHANGE_HOME_DATA:
            return state.set('topicList', fromJS(action.topicList)).set('articleList', fromJS(action.articleList))
        case actionTypes.LOAD_MORE:
            return state.set('articleList', state.get('articleList').concat(fromJS(action.data.articleList)) )
        case actionTypes.TOGGLE_SCROLL_TOP:
            return state.set('showScroll', action.show)
        default:
            return state
    }

}